package com.ruoyi.iot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.iot.domain.IotMasterConfig;
import com.ruoyi.iot.service.IIotMasterConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采集器配置信息Controller
 *
 * @author ruoyi
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/iot/master/config")
public class IotMasterConfigController extends BaseController {
    @Autowired
    private IIotMasterConfigService iotMasterConfigService;

    /**
     * 查询采集器配置信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotMasterConfig iotMasterConfig) {
        startPage();
        List<IotMasterConfig> list = iotMasterConfigService.selectIotMasterConfigList(iotMasterConfig);
        return getDataTable(list);
    }

    /**
     * 导出采集器配置信息列表
     */
    @Log(title = "采集器配置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotMasterConfig iotMasterConfig) {
        List<IotMasterConfig> list = iotMasterConfigService.selectIotMasterConfigList(iotMasterConfig);
        ExcelUtil<IotMasterConfig> util = new ExcelUtil<IotMasterConfig>(IotMasterConfig.class);
        util.exportExcel(response, list, "采集器配置信息数据");
    }

    /**
     * 获取采集器配置信息详细信息
     */
    @GetMapping(value = "/{masterId}")
    public AjaxResult getInfo(@PathVariable("masterId") Long masterId) {
        return success(iotMasterConfigService.selectIotMasterConfigByMasterId(masterId));
    }

    /**
     * 新增采集器配置信息
     */
    @Log(title = "采集器配置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody IotMasterConfig iotMasterConfig) {
        return toAjax(iotMasterConfigService.insertIotMasterConfig(iotMasterConfig));
    }

    /**
     * 修改采集器配置信息
     */
    @Log(title = "采集器配置信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody IotMasterConfig iotMasterConfig) {
        return toAjax(iotMasterConfigService.updateIotMasterConfig(iotMasterConfig));
    }

    /**
     * 删除采集器配置信息
     */
    @Log(title = "采集器配置信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{masterIds}")
    public AjaxResult remove(@PathVariable Long[] masterIds) {
        return toAjax(iotMasterConfigService.deleteIotMasterConfigByMasterIds(masterIds));
    }
}
